﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cwing.UI.Validation;

namespace Cwing.UI.Mvc
{
    public class Configure
    {
        public Int32 Index { get; set; }

        internal String Name { get; set; }

        public String GroupName { get; set; }

        public String ValidationSummaryID { get; set; }

        public String Path { get; set; }

        public Configuration GetConfiguration()
        {
            return ValidationConfigHelper.FetchConfigNode(Path);
        }

        public String ToScript()
        {
            Configuration configuration = GetConfiguration();

            if (configuration == null)
            {
                return String.Empty;
            }
            else
            {
                return String.Format("[{0},\"{1}\",\"{2}\",\"{3}\",\"{4}\",{5},\"{6}\",{7},{8},\"{9}\",\"{10}\",\"{11}\"]",
                   Index, GroupName, "N", Name,
                   ValidationSummaryID,
                   configuration.Mandatory.ToString().ToLower(),
                   configuration.MandatoryMessage, configuration.MinLength, configuration.MaxLength,
                   configuration.LengthMessage, configuration.TypeRegEx.Replace(@"\", @"\\"), configuration.TypeMessage);
            }
        }
    }
}
